//
//  WCDealOrderVC.m
//  CBT
//
//  Created by apple on 2019/7/10.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "WCDealOrderVC.h"
#import "WCOrderDealCell.h"
#import "WCDealOrderView.h"

@interface WCDealOrderVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) WCDealOrderView *dealOrderView;

@end

@implementation WCDealOrderVC


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = kLocalizedString(@"管理收货地址",nil);
    
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.dealOrderView;
    self.tableView.rowHeight = 50;
    [self.tableView registerClass:[WCOrderDealCell class] forCellReuseIdentifier:@"dealCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    if (indexPath.row) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (nil == cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.textLabel.textColor = UIColorFromRGB(0x404040);
            cell.detailTextLabel.font      = [UIFont systemFontOfSize:14];
            cell.detailTextLabel.textColor = UIColorFromRGB(0x404040);
        }
        
        if (indexPath.row == 1) {
            cell.textLabel.text = @"单价";
            cell.detailTextLabel.text = @"0 AKB";
        }
        else {
            cell.textLabel.text = kLocalizedString(@"总计", nil);
            cell.detailTextLabel.text = @"0 AKB";
        }
        
        return cell;
    }
    else {
        WCOrderDealCell *cell = [WCOrderDealCell createTableView:tableView];
        [[cell.plusBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            cell.countLabel.text = [NSString stringWithFormat:@"%ld",[cell.countLabel.text integerValue] + 1];
        }];
        [[cell.jianBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            cell.countLabel.text = [NSString stringWithFormat:@"%ld",[cell.countLabel.text integerValue] + 1];
        }];
        
        return cell;
    }
    
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//
//    WCAddrEditVC *vc = [[WCAddrEditVC alloc] init];
//    [self.navigationController pushViewController:vc animated:YES];
//}

- (UITableView *)tableView {
    if (!_tableView) {
        CGRect rect = self.view.frame;
        rect.size.height -= HFNavigationHeight;
        _tableView = [[UITableView alloc] initWithFrame:rect style:UITableViewStylePlain];
        
        _tableView.delegate     = self;
        _tableView.dataSource   = self;
        _tableView.scrollsToTop = YES;
        
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
        _tableView.tableFooterView = [[UIView alloc] init];
        _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
        
        
        if (@available(iOS 11.0, *)){
            self.tableView.estimatedRowHeight = 0;
            self.tableView.estimatedSectionHeaderHeight = 0;
            self.tableView.estimatedSectionFooterHeight = 0;
        }
        
    }
    return _tableView;
}

- (WCDealOrderView *)dealOrderView {
    if (!_dealOrderView) {
        _dealOrderView = [[WCDealOrderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 160)];
    }
    
    return _dealOrderView;
}

@end

